<?php
namespace app\common\business;

use app\common\lib\Key;
use think\facade\Cache;

class Cart extends BusBase {
    public function insertRedis($userId, $id, $num) {
        // id获取商品数据
        $goodsSku = (new GoodsSku())->getNormalSkuAndGoods($id);
        if (empty($goodsSku)){
            return FALSE;
        }
        $data = [
            'title'=>$goodsSku['goods']['title'],
            'image'=>$goodsSku['goods']['recommend_image'],
            'goods_id'=>$goodsSku['goods']['id'],
            'num'=>$num,
            'create_time'=>time()
        ];
        try {
            $res = Cache::hSet(Key::userCart($userId), $id, json_encode($data));
        } catch (\Exception $e) {
            return FALSE;
        }
        return $res;
    }
}